package com.yyj.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    private static final String SUCCESS = "0";
    private static final String ERROR = "-1";

    //状态
    private String code;
    //返回报错信息
    private String msg;
    //返回数据
    private Object data;

    //成功并且有数据返回
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(SUCCESS);
        result.setData(data);
        return result;
    }

    //成功无数据返回
    public static Result success() {
        Result result = new Result();
        result.setCode(SUCCESS);
        return result;
    }

    //失败
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }
}
